package com.meet.util;

public class Result<T> {

    private Integer code;

    private String message;

    private T data;

    private String errorCode;

    public Result() {

    }

    public Result(Integer code, String message, T data, String errorCode) {

        this.code = code;
        this.message = message;
        this.data = data;
        this.errorCode = errorCode;
    }

    public Result(Integer code, String message) {

        this.code = code;
        this.message = message;
    }

    public Result(Integer code, String message, T data) {

        this.code = code;
        this.message = message;
        this.data = data;
    }

    public Result(Integer code, String message, String errorCode) {

        this.code = code;
        this.message = message;
        this.errorCode = errorCode;
    }

    public Result(Integer code, String message, String errorCode, T data) {

        this.code = code;
        this.message = message;
        this.errorCode = errorCode;
        this.data = data;
    }

    public Result(boolean success, String errcode, String errmsg) {

        if (success) {
            this.code = 200;
            this.errorCode = errcode;
            this.message = errmsg;
        } else {
            this.code = 500;
            this.errorCode = errcode;
            this.message = errmsg;
        }
    }

    public Result(boolean success, int code, String errmsg) {

        if (success) {
            this.code = code;
//            this.errorCode = errcode;
            this.message = errmsg;
        } else {
            this.code = 500;
//            this.errorCode = errcode;
            this.message = errmsg;
        }
    }

    public static <T> Result<T> success() {

        return new Result<>(200, "success");
    }

    public static <T> Result<T> success(T data) {

        return new Result<>(200, "success", data);
    }

    public static <T> Result<T> error(Integer code, String message) {

        return new Result<>(code, message);
    }

    public static <T> Result<T> error(Integer code, String message, String errorCode) {

        return new Result<>(code, message, errorCode);
    }

    public static <T> Result<T> error(Integer code, String message, String errorCode, T data) {

        return new Result<>(code, message, errorCode, data);
    }

    public static <T> Result<T> error(String message) {

        return new Result<>(500, message);
    }

    public static <T> Result<T> error(String message, String errorCode) {

        return new Result<>(500, message, errorCode);
    }

}
